package logic

import (
	"context"
	"fmt"
	"go-zero-demo-04/mall/result/api/internal/svc"
	"go-zero-demo-04/mall/result/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetresultLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetresultLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetresultLogic {
	return &GetresultLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetresultLogic) Getresult(req *types.GetresultRequest) (resp *types.GetresultListResponse, err error) {
	list, err := l.svcCtx.ResultModel.FindSno(l.ctx, req.StudentID)
	if err != err {
		return nil, err
	}

	fmt.Println(list)

	var res []types.GetresultResponse

	for _, item := range list {
		var temp types.GetresultResponse
		temp.StuidentName = item.StuidentName
		temp.StudentID = item.StudentNo
		temp.MBTIcode = item.MbitCode
		temp.Time = item.TestTime
		res = append(res, temp)
	}
	return &types.GetresultListResponse{StudentList: res}, nil

}
